/**********************************************************************************
// Sprite Animation Header
// 
// Creation:	20 Apr 2011
// Updated:		26 Apr 2011
// Compiler:	Visual Studio 2010
//
// Notes:		Defines a sprite animation engine
//              Animations will always be a left to right sequence of frames
//
**********************************************************************************/

#ifndef _ANABELE_ANIMATION_H_
#define _ANABELE_ANIMATION_H_

// make classes and functions exportable to a DLL
#ifdef ANABELE_EXPORTS
#define DLL __declspec( dllexport ) 
#else
#define DLL __declspec( dllimport )
#endif 

/**********************************************************************************/

#include <Windows.h>		// use GetTickCount funcion from Windows API
#include "Types.h"          // use custom engine types

/**********************************************************************************/
// Global Constants and Enumerations

enum AnimMode {ONETIMER, ENDLESS};
 
/**********************************************************************************/

class DLL Animation
{
public:
	float xPos, yPos;			// animation position
	uint currentFrame;			// current selected frame
	bool followMode;			// animation follows sprite position or not
	uint animMode;				// animation mode (ONETIMER or ENDLESS)

private:
	uint startFrame;			// starting frame of the sequence
	uint endFrame;				// final frame of the sequence
	uint animDelay;				// time delay from one frame to another
	ulong timestamp;			// time last animation frame started
	uint * sequence;			// vector with animation sequence	

public:
	Animation(const uint * seq, uint seqSize, uint delay, bool follow, float x=0, float y=0, uint repeat=ONETIMER);	
	~Animation();

	bool Active();				// verify if the current animation is still running
	uint GetFrame();			// get active animation frame 
	void NextFrame();			// pass to next frame 
	void Restart();				// restart animation to initial state
}; 

/**********************************************************************************/
// InLine Member Functions

inline bool Animation::Active()
{ return ((currentFrame < endFrame) || (int(GetTickCount()) < timestamp + animDelay)); }

inline uint Animation::GetFrame()
{  return (sequence ? sequence[currentFrame] : currentFrame); }

inline void Animation::Restart()
{ currentFrame = 0; timestamp = GetTickCount(); }

/**********************************************************************************/

#endif